<!--退换货申请-->
<style>
.alteration-request-form input[type='text'],
.alteration-request-form textarea {
  width: 100%;
  padding: .3em 0 .35em .3em;
  border: 1px solid #ccc;
}
.alteration-request-form textarea {
  resize: vertical;
  min-height: 90px;
}
.alteration-request-form input.error,
.alteration-request-form input:focus,
.alteration-request-form textarea:focus {
  background: #fff;
  border: 1px solid #3cf;
}
.alteration-request-form .submit-btn {
  padding-left: 2em;
  padding-right: 2em;
  margin-bottom: 1em;
}
.alteration-request-form .orange{
  color: #fe8f00;
}
.alteration-request-input li{
  margin: .5em 0;
}
.customer-info {
  background-color: #f2f2f2;
  padding: .5em;
  margin: 1em 0;
}
.customer-info li {
  padding: .2em 0;
}
.customer-info li strong {
  font-weight: normal;
  color: #333;
}
</style>
<div class="heading"><strong><?php echo L('Return_to_apply'); ?></strong></div>
<form action="<?php echo url('partner/request'); ?>" method="post" name="request" class="alteration-request-form js-alteration-request-form">
  <ul class="alteration-request-input">
    <li class="clearfix">
      <div class="align-right col-md-3"><?php echo L('order_sn'); ?></div>
      <div class="col-md-6">
        <input type="text" name="order_sn" placeholder="<?php echo L('input_order_sn'); ?>" autofocus>
      </div>
    </li>
    <li class="clearfix">
      <div class="align-right col-md-3"><?php echo L('productName')?></div>
      <div class="col-md-6">
        <input type="text" name="product_name" placeholder="<?php echo L('input_productName'); ?>">
      </div>
    </li>
    <li class="clearfix">
      <div class="align-right col-md-3"><?php echo L('Return_reason')?></div>
      <div class="col-md-6">
        <textarea name="description" placeholder="<?php echo L('Return_reason_desc'); ?>"></textarea>
      </div>
    </li>
  </ul>
  <div class="clearfix">
    <div class="col-md-6 col-md-push-3">
      <ul class="hide customer-info js-customer-info"></ul>
      <div class="align-center">
        <input type="hidden" name="dosubmit" value="0">
        <button type="submit" class="btn submit-btn"><?php echo L('submit')?></button>
        <p class="orange"><?php echo L('Return_to_apply_tips')?></p>
      </div>
    </div>
  </div>
</form>
<script>
function orderAddress(order_sn) {
  $.ajax({
    type: 'GET',
    url: '/partner/request_ajax',
    data: {'order_sn': order_sn},
    success: function (res) {
      var res = eval('(' + res + ')');
      $('input[name="dosubmit"]').val('0');
      $('.js-customer-info').addClass('hide').html('');

      if (res['error'] == '1') {
        $('input[name="dosubmit"]').val('1');
        $('.js-customer-info').removeClass('hide').html(res['info']);
      } else if (res['error'] == '-1') {
        loction.href = "<?php url('partner/login')?>";
      }
    }
  });
}

$(function () {
  var $alterationRequestForm = $('.js-alteration-request-form');

  $alterationRequestForm.validate({
    submitHandler: function(form) {
      orderAddress($(form).find('input[name=order_sn]').val());
      if ($(form).find('input[name=dosubmit]').val() == '1') {
        form.submit();
      }
    },
    errorElement: 'p',
    errorPlacement: function(error, element) {
      element.after(error);
    },
    rules: {
      order_sn: 'required'
    }
  });

  $alterationRequestForm.find('input[name=order_sn]').on('blur', function() {
    orderAddress($(this).val());
  });
});
</script>